﻿using Common.Service;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using RabitPart.WritedPartApi.Application.Comman.RBACfile;
using RabitPart.WritedPartApi.Application.Comman.RBACfiless;
using RabitPart.WritedPartApi.Application.Comman.TraceabilityFile;

namespace RabitPart.WritedPartApi.Controllers
{
    /// <summary>
    /// 控制器--写api
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class RbacWritedAllController : ControllerBase
    {
        private readonly IMediator mediator;
        private readonly ILogger<RbacWritedAllController> logger;

        public RbacWritedAllController(IMediator mediator, ILogger<RbacWritedAllController> logger)
        {
            this.mediator = mediator;
            this.logger = logger;
        }

        /// <summary>
        /// 添加--用户
        /// </summary>
        /// <param name="model">实体</param>
        /// <returns>添加--用户</returns>
        [HttpPost]
        public async Task<ApiResult> CreateUser(RBACUserCreateComman model)
        {
            try
            {
                return await mediator.Send(model);
            }
            catch (Exception ex)
            {
                logger.LogError("添加用户信息异常" + ex.Message);
                throw;
            }
        }


        /// <summary>
        /// 更新--用户
        /// </summary>
        /// <param name="model">实体</param>
        /// <returns>更新--用户</returns>
        [HttpPost]
        public async Task<ApiResult> UpdateUser(RBACUserUpdateComman model)
        {
            try
            {
                return await mediator.Send(model);
            }
            catch (Exception ex)
            {
                logger.LogError("更新用户信息异常" + ex.Message);
                throw;
            }
        }


        /// <summary>
        /// 删除--用户
        /// </summary>
        /// <param name="model">实体</param>
        /// <returns>删除--用户</returns>
        [HttpPost]
        public async Task<ApiResult> DelecteUser(RBACUserDelecteComman model)
        {
            try
            {
                return await mediator.Send(model);
            }
            catch (Exception ex)
            {
                logger.LogError("s删除用户信息异常" + ex.Message);
                throw;
            }
        }


        /// <summary>
        /// 添加--角色
        /// </summary>
        /// <param name="model">实体</param>
        /// <returns>添加--角色</returns>
        [HttpPost]
        public async Task<ApiResult> CreateRole(RBACRoleCreateComman model)
        {
            try
            {
                return await mediator.Send(model);
            }
            catch (Exception ex)
            {
                logger.LogError("添加--角色信息异常" + ex.Message);
                throw;
            }
        }



        /// <summary>
        /// 更新--角色
        /// </summary>
        /// <param name="model">实体</param>
        /// <returns>更新--角色</returns>
        [HttpPost]
        public async Task<ApiResult> UpdateRole(RBACRoleUpdateComman model)
        {
            try
            {
                return await mediator.Send(model);
            }
            catch (Exception ex)
            {
                logger.LogError("更新--角色信息异常" + ex.Message);
                throw;
            }
        }



        /// <summary>
        /// 删除--角色
        /// </summary>
        /// <param name="model">实体</param>
        /// <returns>删除--角色</returns>
        [HttpPost]
        public async Task<ApiResult> DelectRole(RBACRoleDelecteComman model)
        {
            try
            {
                return await mediator.Send(model);
            }
            catch (Exception ex)
            {
                logger.LogError("删除--角色信息异常" + ex.Message);
                throw;
            }
        }

        /// <summary>
        /// 添加--权限
        /// </summary>
        /// <param name="model">实体</param>
        /// <returns>添加--溯源权限</returns>
        [HttpPost]
        public async Task<ApiResult> Createperm(RBACPermCreateComman model)
        {
            try
            {
                return await mediator.Send(model);
            }
            catch (Exception ex)
            {
                logger.LogError("添加权限信息异常" + ex.Message);
                throw;
            }
        }

        /// <summary>
        /// 修改--权限
        /// </summary>
        /// <param name="model">实体</param>
        /// <returns>修改--溯源权限</returns>
        [HttpPost]
        public async Task<ApiResult> Updateperm(RBACPermUpdateComman model)
        {
            try
            {
                return await mediator.Send(model);
            }
            catch (Exception ex)
            {
                logger.LogError("修改权限信息异常" + ex.Message);
                throw;
            }
        }


        /// <summary>
        /// 删除--权限
        /// </summary>
        /// <param name="model">实体</param>
        /// <returns>删除--溯源权限</returns>
        [HttpPost]
        public async Task<ApiResult> Delecteperm(RBACPermDelecteComman model)
        {
            try
            {
                return await mediator.Send(model);
            }
            catch (Exception ex)
            {
                logger.LogError("删除权限信息异常" + ex.Message);
                throw;
            }
        }
         

    }
}
